package response

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Response struct {
	StatusCode int         `json:"statusCode"`
	Code       int         `json:"code"`
	Data       interface{} `json:"data"`
	Msg        string      `json:"msg"`
}

const (
	ERROR   = 0
	SUCCESS = 1
)

func Result(c *gin.Context, statusCode int, code int, data interface{}, msg string) {
	// 开始时间
	c.JSON(statusCode, Response{
		statusCode,
		code,
		data,
		msg,
	})
}

func ResOk(c *gin.Context, data interface{}) {
	Result(c, http.StatusOK, SUCCESS, data, "操作成功")
}
func ResWarn(c *gin.Context, msg string) {
	Result(c, http.StatusOK, ERROR, nil, msg)
}
func ResMsg(c *gin.Context, msg string) {
	Result(c, http.StatusOK, SUCCESS, nil, msg)
}
func ResErr(c *gin.Context, statusCode int, msg string) {
	Result(c, statusCode, ERROR, nil, msg)
}

func ResMsgOk(c *gin.Context, data interface{}, msg string) {
	Result(c, http.StatusOK, SUCCESS, data, msg)
}

func ResMsgErr(c *gin.Context) {
	Result(c, http.StatusOK, ERROR, nil, "操作失败")
}
